﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Liang.DataBase.Model;
using Liang.DataBase.Tools;
using Liang.Model;
using Liang.UI;
using Liang.Util.Crypt;
using Client.Helper;
using Liang.DataBase.Helper;

namespace Client
{
    public partial class FormEditPassword : Form
    {
        public FormEditPassword()
        {
            InitializeComponent();
        }

        private void button_ok_Click(object sender, EventArgs e)
        {
            string strOldPassword = AppHelper.DecPassword(UserManager.loginedUser.password);

            if (0 != string.Compare(strOldPassword, textBoxEx_oldPwd.Text))
            {
                MessageBoxEx.Show(this, "密码不正确");
                return;
            }

            if (string.IsNullOrEmpty(textBoxEx_newPwd.Text))
            {
                MessageBoxEx.Show(this, "密码不能为空");
                return;
            }

            if (0 != string.Compare(textBoxEx_newPwd.Text, textBoxEx_confirm.Text))
            {
                MessageBoxEx.Show(this, "两次输入的密码不一致");
                return;
            }

            string pwd = AppHelper.EncPassword(textBoxEx_newPwd.Text);
            if (!UserManager.EditPassword(UserManager.loginedUser.userId.ToString(), pwd))
            {
                MessageBox.Show("修改密码失败");
                return;
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close();
        }

        private void button_cancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
